﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ValidationEngine.Commons;
using ValidationEngine.Tools;
using ValidationEngineXTest.Models;

namespace ValidationEngineXTest.UI
{
    class TestViewPresenter
    {
        private ITestView _view;
        private IValidationProvider _vp = new ValidationProvider();
        
        public TestViewPresenter(ITestView view)
        {
            if (null == view)
            {
                throw new ArgumentNullException("view");
            }
            this._view = view;
            this._view.OnSave += view_OnSave;
            this._vp.View = _view;

            this._view.Source.DataSource = new Product
            {
                Name = "test"
            };
        }

        void view_OnSave()
        {
            _vp.ValidateModel(ctx: ValidationEngine.Commons.Enums.RuleApplingContext.OnSave);
            MessageBox.Show(String.Format("Is {0}valid", _vp.IsModelValid ? "" : "not "));
        }
    }
}
